package com.qf.voterabbitmqcustomer.voteLogs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.voterabbitmqcustomer.voteLogs.entity.VoteLogs;
import com.qf.voterabbitmqcustomer.voteLogs.mapper.VoteLogsMapper;
import com.qf.voterabbitmqcustomer.voteLogs.service.IVoteLogsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lx
 * @since 2023-03-02
 */
@Service
public class VoteLogsServiceImpl extends ServiceImpl<VoteLogsMapper, VoteLogs> implements IVoteLogsService {


    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void saveVoteLogs(String msg) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        List<VoteLogs> voteLogs = objectMapper.readValue(msg, new TypeReference<List<VoteLogs>>() {
        });
        saveBatch(voteLogs);
    }
}
